##图像分割实例：
# 图像分割案例：https://blog.csdn.net/G_redsky/article/details/136271687
# 图像分割算法：https://blog.csdn.net/qq_53529450/article/details/136644724
import cv2 as cv
# 读取图像
image = cv.imread('../imgs/tuxiangfenge3.png')
# 转换为灰度图像
gray = cv.cvtColor(image, cv.COLOR_BGR2GRAY)
# 应用全局阈值化(筛选出)
_, thresh = cv.threshold(gray, 127, 255, cv.THRESH_BINARY)
# 查找轮廓
contours, _ = cv.findContours(thresh, cv.RETR_EXTERNAL, cv.CHAIN_APPROX_SIMPLE)
# 遍历轮廓并画出轮廓
cv.drawContours(image, contours, -1, (0, 255, 0), 3)
# 显示图像
cv.imshow('Segmented Image', image)
cv.waitKey(0)
cv.destroyAllWindows()